//
//  HistoryOfTheSurveyViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/5/29.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "HistoryOfTheSurveyViewController.h"
#import "TestQuestionsReportViewController.h"
@interface HistoryOfTheSurveyViewController (){
    
    int a;
    NSArray * arr;
    CGSize  actualsize;
}

@end

@implementation HistoryOfTheSurveyViewController



-(void)viewDidAppear:(BOOL)animated{
    
    
    
    ////NSLog(@"13321312312%@",self.dic);
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏头文字
    self.navigationItem.title = @"评测题目";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#44afd7" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.view.backgroundColor = [UIColor whiteColor];

    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    //NSLog(@"%@",self.allkey);
    
    [self subView];

    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
   
    

}
-(void)turntolast{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}
-(void)subView{

    
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, NavbarHight+34, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
    [self.view addSubview:lineView];
    
    
    UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/3*2, NavbarHight, 1, 34)];
    downView.backgroundColor = UIColorWithRGBA(215, 215, 215, 1);
    [self.view addSubview:downView];
    

    UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight, SCREEN_WIDTH/3*2, 30)];
    timeLab.text = @"评测题目";
    timeLab.font = [UIFont systemFontOfSize:15];
    timeLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:timeLab];
    
    UILabel * typeLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/3, 30)];
    typeLab.text = @"答案";
    typeLab.font = [UIFont systemFontOfSize:15];
    typeLab.textAlignment = NSTextAlignmentCenter;
    [downView addSubview:typeLab];
    
    _HistoryOfTheSurveyTabView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavbarHight+35, SCREEN_WIDTH, SCREEN_HEIGHT-NavbarHight-40) style:UITableViewStylePlain];
    _HistoryOfTheSurveyTabView.delegate = self;
    _HistoryOfTheSurveyTabView.dataSource = self;
//    _HistoryOfTheSurveyTabView.rowHeight = 87/2;
    _HistoryOfTheSurveyTabView.tableFooterView=[[UIView alloc]init];
    [self.view addSubview:_HistoryOfTheSurveyTabView];
    
    
    
}
#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.allkey.count;
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    for (int i = 0; i<self.allval.count; i++) {
        
        if (indexPath.row == i) {
            
            
            UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH/3*2, 87/2)];
            NSString * tstring =[NSString stringWithFormat:@"   第%d题:%@",indexPath.row+1,self.allval[i]];
            titiLab.numberOfLines =0;
            UIFont * tfont = [UIFont systemFontOfSize:12];
            titiLab.font = tfont;
            titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
            titiLab.text = tstring ;
            [titiLab setBackgroundColor:[UIColor whiteColor]];
            
            CGSize size =CGSizeMake(SCREEN_WIDTH/3*2,MAXFLOAT);
            NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
            actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
            titiLab.frame =CGRectMake(5,5, actualsize.width, actualsize.height);
            
            
            return  actualsize.height+10;

            
        }
            
    }
    
    return 10;
        
    
}



#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *NOTIFY = @"cell";
//    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
        
        _HistoryOfTheSurveyTabView.separatorStyle = UITableViewCellEditingStyleNone;

        for (int i = 0; i<self.allval.count; i++) {
            
            if (indexPath.row == i) {
                
                UILabel * titiLab = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, SCREEN_WIDTH/3*2, 87/2)];
                NSString * tstring =[NSString stringWithFormat:@"   第%d题:%@",indexPath.row+1,self.allval[i]];
//                NSString * tstring =@"11111111111111111111111";

                titiLab.numberOfLines =0;
                UIFont * tfont = [UIFont systemFontOfSize:12];
                titiLab.font = tfont;
                titiLab.lineBreakMode =NSLineBreakByTruncatingTail ;
                titiLab.text = tstring ;
                [titiLab setBackgroundColor:[UIColor whiteColor]];
                [cell addSubview:titiLab];
                
                CGSize size =CGSizeMake(SCREEN_WIDTH/3*2,MAXFLOAT);
                NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
                actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
                titiLab.frame =CGRectMake(5,0, actualsize.width, actualsize.height);

                
//                _HistoryOfTheSurveyTabView.rowHeight = actualsize.height+10;
                
                UILabel * numberLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/3*2, 5, SCREEN_WIDTH/3, 20)];
                
                
                numberLab.font = [UIFont systemFontOfSize:12];
                numberLab.text = [NSString stringWithFormat:@"%@",self.allkey[i]];
                numberLab.adjustsFontSizeToFitWidth = YES;
                numberLab.textAlignment = NSTextAlignmentCenter;
                [cell addSubview:numberLab];

                
                
            }
            
            
        }
        
        
        
        
        
   
        
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
        view.backgroundColor = UIColorWithRGBA(229, 229, 231, 1);
        [cell addSubview:view];
        
    }

    
    
    
    
    
    
    return cell;
    
    
    
    
    
}
-(void)rightBtnClick{
    
    
    
    
}
#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}
#pragma mark--- tableViewDelegat 点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
  
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
